//书籍内容的规则
import 'dart:convert';

import 'package:flutter_book/data/model/yck/rule/rule.dart';


class BookInfoRule {
  Rule? init;
  Rule? name;
  Rule? author;
  Rule? intro;
  Rule? kind;
  Rule? lastChapter;
  Rule? updateTime;
  Rule? coverUrl;
  Rule? tocUrl;
  Rule? wordCount;
  Rule? canReName;

  BookInfoRule(this.init, this.name, this.author, this.intro, this.kind, this.lastChapter, this.updateTime,
      this.coverUrl, this.tocUrl, this.wordCount, this.canReName);

  BookInfoRule.fromJson(dynamic json) {
    json = checkJson(json);
    init = json['init'];
    name = json['name'];
    author = json['author'];
    intro = json['intro'];
    kind = json['kind'];
    lastChapter = json['lastChapter'];
    updateTime = json['updateTime'];
    coverUrl = json['coverUrl'];
    tocUrl = json['tocUrl'];
    wordCount = json['wordCount'];
    canReName = json['canReName'];
  }

  Map<String, dynamic> toJson() {
    var map = <String, dynamic>{};
    map['init'] = init;
    map['name'] = name;
    map['author'] = author;
    map['intro'] = intro;
    map['kind'] = kind;
    map['lastChapter'] = lastChapter;
    map['updateTime'] = updateTime;
    map['coverUrl'] = coverUrl;
    map['tocUrl'] = tocUrl;
    map['wordCount'] = wordCount;
    map['canReName'] = canReName;
    return map;
  }

  Map<String,dynamic> checkJson(dynamic jsonString){
    if (jsonString == null) {
      jsonString =Map();
    }else if(jsonString is String){
      try{
        jsonString = json.decode(jsonString);
        if(!(jsonString is Map<String,dynamic>)){
          jsonString =Map();
        }
      }catch (e){
        jsonString =Map();
      }
    }else if(jsonString is BookInfoRule){
      jsonString = jsonString.toJson();
    }else if(!(jsonString is Map<String,dynamic>)){
      jsonString =Map();
    }
    return jsonString;
  }

}
